package com.gaswell.canal.chain;

import cn.hutool.extra.spring.SpringUtil;
import com.gaswell.utils.RedisEnumeration;
import com.gaswell.utils.SpringUtils;
import javafx.application.Application;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.Set;

/**
 * @ClassName RedisCleanHandler
 * @Author xiaow
 * @DATE 2024/6/6 16:16
 **/
public class RedisCleanHandler extends Handler {
    RedisTemplate redisTemplate;

    public RedisCleanHandler() {
        this.successor = null;
    }

    @Override
    public void handleRequest(Object object) {
        if (redisTemplate == null)
            redisTemplate= (RedisTemplate) SpringUtils.getBean("redisTemplate");
        String name = object.getClass().getName();
        String[] split = name.split("\\.");
//      获取类名
        String className = split[split.length - 1];

        if (className.equals("Diagnosis")) {
            Set keys = redisTemplate.keys(RedisEnumeration.QBA01INSPECTION + "*");
            redisTemplate.delete(keys);
        }


        if (this.successor != null) {
            this.successor.handleRequest(object);
        }
    }
}
